<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
          integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://lib.baomitu.com/jquery/3.3.1/jquery.min.js"></script>

    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="https://lib.baomitu.com/layer/3.1.1/layer.js"></script>
    <script>
        function ajaxPost() {
            var username = $("#username").val();
            var password = $("#password").val();

            if (username == '') {
                layer.msg('请输入用户名');
                return false;
            }
            if (password == '') {
                layer.msg('请输入密码');
                return false;
            }

            var formData = $("#myform").serialize();
            $.ajax({
                type: "post",
                url: "{:url('index/loginFun')}",
                data: formData,//data传递过去
                success: function (data) {
                    if (data == 0) {
                        layer.msg('用户名密码错误');

                    } else if (data == 1) {
                        layer.msg('登陆成功', {
                            icon: 16
                            , shade: 0.01
                        });

                        function jump() {
                            window.location.href = "{:url('index/mian')}";
                        }
                        setTimeout(jump, 1000);

                    } else {
                        layer.msg('账号密码错误')
                    }
                }

            });

        }
    </script>

    <title>进销存管理系统</title>
</head>
<body>

<div class="container">
    <div class="row">
        <div class="col-md-4">
            <br>
        </div>
        <div class="col-md-4">
            <div class="m-4">
                <br><br><br>
                <form id="myform" class="form-signin">
                    <h2 class="form-signin-heading">进销存管理系统</h2>
                    <br>
                    <label for="username" class="sr-only">用户名</label>
                    <input type="text" id="username" name="username" class="form-control mb-2" placeholder="用户名"
                    >
                    <label for="password" class="sr-only">密码</label>
                    <input type="password" id="password" name="password" class="form-control" placeholder="密码"
                    >

                    <br>
                    <button class="btn btn-lg btn-primary  btn-block" type="button" onclick="ajaxPost()">登录</button>
                </form>
            </div>
        </div>
        <div class="col-md-4">
            <br>
        </div>
    </div>
</div>


</body>
</html>